import {
    SET_CATEGORY_INFO,
    SET_MENULIST,
    SET_BRAND_INFO,
    SET_CARNOUSEL_PIC,
    HIDDEN_SUB,
    SHOW_SUB,
} from './actionsType'

export default {
    [SET_CATEGORY_INFO](state, categoryList) {
        state.categoryList = categoryList
    },
    // 设置左侧菜单栏数据
    [SET_MENULIST](state) {
        const list = state.categoryList.map((lItem) => {
            return {
                id: lItem.id,
                name: lItem.name,
                children: lItem.children && lItem.children.slice(0, 2),
                goods: lItem.goods
            }
        })
        list.push(state.brandInfo)
        state.menuList = list
    },
    // 设置品牌数据
    [SET_BRAND_INFO](state, brands) {
        state.brandInfo.brands = brands
    },
    // 设置轮播图数据
    [SET_CARNOUSEL_PIC](state, sliders) {
        state.sliders = sliders
    },
    [SHOW_SUB](state, id) {
        const category = state.categoryList.find(fItem => fItem.id === id)
        category.open = true
    },
    [HIDDEN_SUB](state, id) {
        const category = state.categoryList.find(fItem => fItem.id === id)
        category.open = false
    }
}